using System;
using System.Text.RegularExpressions;

namespace ComBrowser
{


	public class Commentary
	{

		BookCollection bookCollection=null;
		
		public int ID { get; set; }
		public int Book { get; set; }
		public int Chapter { get; set; }
		public int Verse { get; set; }
		public string Body { get; set; }
		public string BodyText { get; set; }
		public int ResultID {get;set;}
		
		
		public string DisplayTitle {
			get {
				if (bookCollection == null)
					bookCollection = BookCollection.Instance ();
				
				string retVal = null;
				
				retVal = string.Format ("{0} {1}", bookCollection[Book - 1].Long, Chapter);
				
				if (this.Verse > 0)
					retVal += ":" + this.Verse;
				
				return retVal;
			}
			
		}

		public string QueryBody (string query)
		{
			string retVal = "";
			Regex reg = new Regex ("(?<before>.{0,35})" + query + "(?<after>.{0,200})");
			Match match = reg.Match (this.Body);
			if (match.Success)
			{
				retVal = string.Format ("...{0}{1}{2}", match.Groups["before"].Value, query, match.Groups["after"].Value);
			}
			return retVal;
		}
	}
}
